<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
${aier_doctype}
<html <s:property value="aier_html_xmlns" escape="false"/>>
<head>
<meta http-equiv="Content-Type" content="${aier_content_type}" />
<meta name="keywords" content="${aier_keyworks}" />
<meta name="description" content="${aier_description}" />
<link rel="stylesheet" href="${aier_css_url}${aier_jqui_css}ui.css" />
<link href="${aier_css_url}jq/jq.css" rel="Stylesheet" />
<link rel="stylesheet" href="${aier_css_url}social/module/jq-msg.css" />
<link rel="stylesheet" href="${aier_css_url}comm/text.css" />
<link rel="stylesheet" href="${aier_css_url}proxy/apc.css" />
<!-- 
<script type="text/javascript" src="${aier_js_url}j.js"></script>
<script type="text/javascript" src="${aier_js_url}b.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/hh/ui.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/msg.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/hh/dialog.js"></script>
<script type="text/javascript" src="${aier_js_url}97/WdatePicker.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/cn.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/jq.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/block.js"></script>
<script type="text/javascript" src="${aier_js_url}comm/text.js"></script>
 -->
<script type="text/javascript" src="${aier_js_url}j.js"></script>
<script type="text/javascript" src="${aier_js_url}b.js"></script>
<script type="text/javascript" src="${aier_js_url}${aier_jqui_js}ui.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/msg.js"></script>
<script type="text/javascript" src="${aier_js_url}97/WdatePicker.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/cn.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/jq.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/ja.js"></script>
<script type="text/javascript" src="${aier_js_url}jc/cj.js"></script>
<script type="text/javascript" src="${aier_js_url}${aier_jqui_js}custominput.js"></script>
<script type="text/javascript" src="${aier_js_url}${aier_jqui_js}text.js"></script>

<title>创建子级代理商</title>

<script type="text/javascript">
var ptype = "${ptype}";
$(document).ready(function(){          
	$("#proSubinfo").jqGrid({                
		url:'${aier_url}${aier_urijs}proxy_sub_load${aier_suffix}?pid=${pid}',                
		datatype:"json",                
		mtype:'GET',
		weigth:500,	
		height:230,  
		colNames:['代理商编号','代理商名称','删除','分派卡'],//,'回收卡'],                
		colModel:[                    
		{name:'pid',index:'pid',width:250,sortable:false,align:'center'},                    
		{name:'name',index:'name',width:250,sortable:false,align:'center'},
		{name:'remove',index:'pid',width:120,sortable:false,align:'center'},
		{name:'assign',index:'pid',width:120,sortable:false,align:'center'}
		//{name:'reback',index:'pid',width:120,sortable:false,align:'center'}
		],
		//autowidth:true,
		jsonReader: {
			root:"subProxys",
			page: "page",
			total: "page_count",
			records : "count",
			repeatitems: false
		},
		pager: jQuery("#proSubpage"),
		prmNames : {page:"page",sort: "sort"},
		rowNum: 10,
		//rowList: [10, 20, 30],
		sortname: 'pid',
		hidegrid: false,
		sortorder: 'asc',
		viewrecords: true,
		caption: '子级代理商',
		gridComplete:function(){
			var ids=jQuery("#proSubinfo").jqGrid('getDataIDs');
			for(var i=0; i<ids.length; i++){
				var id=ids[i];   
				del = "<a href='javascript:;' class='jqtrow' onclick='delTel(" + id + ")'>删除</a>"; 
				ass = "<a href='javascript:;' class='jqtrow' onclick='assTel(" + id + ")'>卡管理</a>"; 
				//reb = "<a href='javascript:;' class='jqtrow' onclick='rebTel(" + id + ")'>回收卡</a>"; 
				//,reback:reb	
				jQuery("#proSubinfo").jqGrid('setRowData', ids[i], { remove: del,assign:ass});
			}
		}
	}).navGrid("#proSubpage", { edit: false, add: false, del: false, search: false });
});

//删除代理商
function delTel(id){
	 $("#deltname").html(" "+jQuery("#proSubinfo").jqGrid('getRowData', id).name);
	 $(function() {
			$( "#sub_del" ).dialog({
				modal: true,
				resizable: false,
				buttons: {
					"删除": function() {
						var fundel = function(data1){
							if(1==data1.s){
								$().message("删除成功!");
								 $("#proSubinfo").trigger("reloadGrid");
								 $("#sub_del").dialog( "close" );
							}else{
								$().message("删除失败!");
							}
						};
						exeAjax(ajaxUrl("${aier_url}${aier_urijs}proxy_sub_deleteSubProxy${aier_suffix}"), fundel, {"pid_delete" :jQuery("#proSubinfo").jqGrid('getRowData', id).pid});
					},"取消": function() {
						$( this ).dialog( "close" );
					}
				}
			});
		});
}

function assTel(id){
	var pid_delete = jQuery("#proSubinfo").jqGrid('getRowData', id).pid;
	$("#d_card").dialog({
		//背景变暗
		modal: true,
		resizable: false,
		show : "blind",
		//hide : "explode",
		width : "635",
		height : "180",
		buttons: {
			"分派": function() {
				var body_begin = $("#txt_body_begin").val();
				var body_end = $("#txt_body_end").val();
				var ic_head_add = $('#headadd_types  option:selected').val();
				var funass = function(data1){
					if(1==data1.s){
						$().message("分派成功!");
						 //$("#proSubinfo").trigger("reloadGrid");
					}else{
						$().message("分派失败!"+data1.error_info);
					}
				};
				exeAjax(ajaxUrl("${aier_url}${aier_urijs}proxy_sub_assignSubCard${aier_suffix}"), funass, 
					{"pid":"${pid}","pid_delete":pid_delete,"body_begin":body_begin,"body_end":body_end,"ic_head_add":ic_head_add});
			},
			"回收": function() {
				var body_begin = $("#txt_body_begin").val();
				var body_end = $("#txt_body_end").val();
				var ic_head_add = $('#headadd_types  option:selected').val();
				var funreb = function(data1){
					if(1==data1.s){
						$().message("回收成功!");
						 //$("#proSubinfo").trigger("reloadGrid");
					}else{
						$().message("回收失败!"+data1.error_info);
					}
				};
				exeAjax(ajaxUrl("${aier_url}${aier_urijs}proxy_sub_rebackSubCard${aier_suffix}"), funreb, 
					{"pid":"${pid}","pid_delete":pid_delete,"body_begin":body_begin,"body_end":body_end,"ic_head_add":ic_head_add});
			},
			"取消": function() {
				$( this ).dialog( "close" );
			}
		}
	});
}

</script>
</head>
<body>
	<div id="tabs">
		<ul>
			<li><a href="#tabs-1">创建子级代理商</a>
			</li>
		</ul>
		<div id="tabs-1" style="height: 500px;">
			<div class="d_content">
				<div>
					<div class="d_scnOut" >
						<div class="d_scname">
							<label>分派区域:</label>
						</div>
						<div class="sel_position">
							<select id="area_types" onchange='loadcity(this,0)'>
								<c:forEach var="procity" items="${proCityList }">
									<option value="${procity.cid}">${procity.cname}</option>
								</c:forEach>
							</select>
							<span id="si_region_p" style="display:none"></span>
							<span id="si_region_c" style="display:none"></span>
							<span id="si_region_a" style="display:none"></span>
							<span id="si_region_t" style="display:none"></span>
							<span id="si_region_t"></span>
						</div>
					</div>
					<div class="d_scnOut" style="margin-top: 0px;">
						<div class="d_scname">
							<label>账号:</label>
						</div>
						<div class="d_sctext">
							<input type="text" id="txt_account_add" class="txt_scname">
						</div>

					</div>

					<div style="margin-left: 250px;margin-top: -40px;">
						<div class="d_scnOut">
							<div class="d_scname">
								<label>名称:</label>
							</div>
							<div class="d_sctext">
								<input type="text" id="txt_name_add" class="txt_scname">
							</div>
						</div>
					</div>
					
					<button id="b_apcAssign" onclick="addSub()"
						style="margin-left: 600px;margin-top: 0px;"
						class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
						role="button" aria-disabled="false">
						<span class="ui-button-text">添加</span>
					</button>
					<button id="b_apcAssign" onclick="addSub_jxs()"
						style="margin-left: 683px;margin-top: -51px;"
						class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
						role="button" aria-disabled="false">
						<span class="ui-button-text">添加经销商</span>
					</button>
					<div id="sub_del" style="display: none;" title="删除代理商">
						您确定要将代理商<span id="deltname"></span> 删除吗?
					</div>
				</div>
				
				<div style="margin-top: 0px;margin-left: 50px;">
					<table id="proSubinfo"></table>
					<div id="proSubpage"></div>
				</div>
				
				<!-- 弹出层内容 -->
				<div id="d_card" style="display: none;" title="卡管理">
					
					<div style="margin-top: 30px;">
						<div class="d_scnOut">
							<div class="d_scname">
								<label>卡前缀:</label>
							</div>
							<div class="sel_position">
								<select id="headadd_types">
									<c:forEach var="head" items="${head_searchList }">
										<option value="${head.ichead}">${head.ichead}</option>
									</c:forEach>
								</select>
							</div>
						</div>
						<div class="d_scnOut" style="margin-top: -38px;margin-left: 250px;">
							<div class="d_scname">
								<label>卡范围:</label>
							</div>
							<div class="d_ictext">

								<input type="text" id="txt_body_begin" class="txt_scname">
							</div>
							<div class="d_scname"
								style="margin-left: 90px;margin-top: -20px;">
								<label>到</label>
							</div>
							<div class="d_ictext" style="margin-left: 213px;">
								<input type="text" id="txt_body_end" class="txt_scname">
							</div>
							
						</div>
					</div>
				</div>
				
				
				
				
				
				
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
	$("#tabs").tabs();
	
	//添加子级代理商
	function addSub(){
		var pid = "${pid}";
		var cid_add = $('#area_types  option:selected').val(); 	
		var name_add = $('#txt_name_add').val();
		var account_add = $('#txt_account_add').val();
		if(acity.cid!=-1){
			cid_add = acity.cid;
		}
		if(ptype==4){
			$().message("您是经销商,无权限添加子级代理商");
			return
		}
		if(account_add.trim()==""){
			$().message("请输入账号");
			return
		}
		if(name_add.trim()==""){
			$().message("请输入子级代理商的名称");
			return
		}
		var fun = function(data){
			if(data.s==1){
				$().message("添加子级代理商成功");
				$("#proSubinfo").trigger("reloadGrid");
			}else{
				$().message("添加子级代理商失败:"+data.error_info);
			}
		};
		exeAjax(ajaxUrl("${aier_url}${aier_urijs}proxy_sub_addSubProxy${aier_suffix}"), fun, 
			{"pid" :pid,"cid_add" : cid_add,"name_add":name_add,"account_add":account_add,"ptype":ptype});
	}
	
	//添加经销商
	function addSub_jxs(){
		var pid = "${pid}";
		var cid_add = $('#area_types  option:selected').val(); 	
		var name_add = $('#txt_name_add').val();
		var account_add = $('#txt_account_add').val();
		if(acity.cid!=-1){
			cid_add = acity.cid;
		}
		if(ptype==4){
			$().message("您是经销商,无权限添加经销商");
			return
		}
		if(account_add.trim()==""){
			$().message("请输入账号");
			return
		}
		if(name_add.trim()==""){
			$().message("请输入子级代理商的名称");
			return
		}
	
		var fun = function(data){
			if(data.s==1){
				$().message("添加经销商成功");
				$("#proSubinfo").trigger("reloadGrid");
			}else{
				$().message("添加经销商失败:"+data.error_info);
			}
		};
		exeAjax(ajaxUrl("${aier_url}${aier_urijs}proxy_sub_addSubJxsProxy${aier_suffix}"), fun, 
			{"pid" :pid,"cid_add" : cid_add,"name_add":name_add,"account_add":account_add});
	}

</script>

<!-- 加载代理商分派区域 -->
<script type="text/javascript">
function class_acity(dvid){this.a_dvid=dvid;}
	var acity= new class_acity("si_region");
	
	class_acity.prototype.load=function(me,cid,flag){
		var dvid=this.a_dvid;
		var thisme=this;
		this.cid=cid;
		if(!isnull(me)){
			this.cname=me.options[me.selectedIndex].text;
		}
		
		var fun=function(data){
			var ct=data.ct;
			thisme.subname=data.subname;
			
			if(1==data.s){
			initsp();
			
			var cl=data.cl;
				var lselid="";
				switch(ct){
				case 0:
					$("#"+dvid+"_p").show();
					lselid="s_"+dvid+"_p";
					break;
				case 10:
					if(data.count<=0&&ct>0){return;}
					$("#"+dvid+"_c").show();
					lselid="s_"+dvid+"_c";
					break;
				case 20:
					if(flag==1) {
						$("#"+dvid+"_c").show();
					}
					if(data.count<=0&&ct>0){return;}
					$("#"+dvid+"_a").show();
					lselid="s_"+dvid+"_a";
					break;
				case 30:
					if(flag == 1) {
						$("#"+dvid+"_c").show();
						$("#"+dvid+"_a").show();
					}
					if(data.count<=0&&ct>0){return;}
					$("#"+dvid+"_t").show();
					lselid="s_"+dvid+"_t";
					break;
				}
				createSel(dvid,ct);				
				loadsel(lselid,"-1","请选择",true);
				for (var index in cl) {
					loadsel(lselid,index,cl[index],false);
				}
			}else{
				switch(ct){
				case 0:
					initsp();
					$("#"+dvid+"_p").show();
					loadsel("s_"+dvid+"_p","-1","无数据",true);
					break;
				case 10:
					initsp();
					$("#"+dvid+"_c").show();
					loadsel("s_"+dvid+"_c","-1","无数据",true);
					break;
				case 20:
					initsp();
					$("#"+dvid+"_a").show();
					loadsel("s_"+dvid+"_a","-1","无数据",true);
					break;
				case 30:
					initsp();
					$("#"+dvid+"_t").show();
					loadsel("s_"+dvid+"_t","-1","无数据",true);
					break;
				}
			}
		};
		
		exeAjax(ajaxUrl("${aier_url}commonjs/cityutil${aier_suffix}"), fun, {"cityid" :cid});
		
		function initsp(){
		    $("#"+dvid+"_p").hide();$("#"+dvid+"_c").hide();$("#"+dvid+"_a").hide();$("#"+dvid+"_t").hide();
      	}
      	
      	function loadsel(id,v,c,init){
      		if(init){$("#"+id).html("");}
      		$("#"+id).append('<option value="'+v+'">'+c+'</option>'); 
      	}
      	
      	function createSel(id,ct){
      		var sid="";
      		var selid="";
      		switch(ct){
      		case 0:sid=id+"_p";selid="s_"+id+"_p";break;
      		case 10:sid=id+"_c";selid="s_"+id+"_c";break;
      		case 20:sid=id+"_a";selid="s_"+id+"_a";break;
      		case 30:sid=id+"_t";selid="s_"+id+"_t";break;
      		}
      		$("#"+sid).html("<select id='"+selid+"' onchange='loadcity(this,1)'></select>");
      	}
	};
	function loadcity(me,flag){
		acity.load(me,me.value,flag);
	}
	
	loadcity(document.getElementById("area_types"),0);
	
</script>

</html>